interface TreeNode<T> {
    val: T
    left?: TreeNode<T>
    right?: TreeNode<T>
}


namespace _275 {

var binaryTreePaths = function(root: TreeNode<number>): string[] {
    if (root === null) return [];
    let left = binaryTreePaths(root.left)
    let right = binaryTreePaths(root.right)
    var result = left.concat(right).map(
        tail => root.val + "->" + tail
    )
    return result.length === 0 ? [ root.val.toString() ] : result;
    // return root === null ? [] : 
    //     binaryTreePaths(root.left)
    //         .concat( binaryTreePaths(root.right))
    //         .map(tail => root.val + "->" + tail);
};

var input257: TreeNode<number> = {
    val: 1,
    left: {
        val: 2,
        left: null,
        right: {
            val: 5,
            left: null,
            right: null
        }
    },
    right: {
        val: 3,
        left: null,
        right: null
    }
} 
var answer257 = binaryTreePaths( input257)

console.log('The End');

}